﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SolutionModel;
using SFast.DB;
using SolutionDAL;

namespace SolutionBLL
{
    public class T_AdminUserBLL
    {

        #region 通过用户ID获取用户信息
        /// <summary>
        /// 通过用户ID获取用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<T_AdminUser> GetAdminUserByID(String id)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            return dal.GetAdminUserByID(id);

        }
        #endregion

        #region 通过用户ID获取用户信息 转换为js 回填到表单中
        /// <summary>
        /// 通过用户ID获取用户信息 转换为js 回填到表单中
        /// 标记：需修改
        /// </summary>
        /// <param name="id">要查找的用户ID</param>
        /// <returns></returns>
        public void GetAdminUserByIDToJs(String id)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            dal.GetAdminUserByID(id);
        }
        #endregion

        #region 添加管理员
        /// <summary>
        /// 添加管理员
        /// </summary>
        /// <param name="obj">管理员实体</param>
        /// <pparam name="roleids">当前管理员所属的角色ID,字符串格式，用逗号分割</pparam>
        public void InsertAdminUser(T_AdminUser obj, String roleids)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            dal.InsertAdminUser(obj, roleids);
        }
        #endregion

        #region 更新管理员信息
        /// <summary>
        /// 更新管理员信息
        /// 标记：需修改
        /// </summary>
        /// <param name="userobj">要修改的对象</param>
        /// <param name="roleID">字符串以逗号分割的角色ID</param>
        /// <returns></returns>
        public bool UpdateAdminUser(T_AdminUser userobj, String roleID)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            return dal.UpdateAdminUser(userobj, roleID);

        }
        #endregion

        #region 获取用户列表
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        public Pagination GetAdminUserPage(int size)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            IQueryable<T_AdminUser> user = dal.GetAdminUserList("");
            return user._ToPagination(size);
        }

        /// <summary>
        /// 获取所有用户
        /// </summary>
        /// <param name="key">用户名、用户姓名关键词</param>
        public List<T_AdminUser> getAdminUserAll(String key)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            IQueryable<T_AdminUser> user = dal.GetAdminUserList(key);
            return user.ToList();
        }
        #endregion

        #region 显示所有用户，指定角色下的用户不显示
        /// <summary>
        /// 显示所有用户，指定角色下的用户不显示
        /// 用于角色列表页-- 用户列表（添加）弹出窗
        /// </summary>
        /// <param name="key">关键词</param>
        /// <param name="roleId">指定角色下的用户不显示</param>
        /// <returns></returns>
        public List<T_AdminUser> getAdminUserAll(String key, String roleId)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            IQueryable<T_AdminUser> user = dal.GetAdminUserList(key);
            user = user.Where(o => o.T_UsersInRoles.Where(u => u.RoleID == roleId).Count()==0);
            List<T_AdminUser> aa = user.ToList();
            return aa;
        }
        #endregion

        #region 添加用户时验证当前用户是否已经在数据库存在
        /// <summary>
        /// 添加用户时验证当前用户是否已经在数据库存在
        /// </summary>
        /// <param name="account">用户名</param>
        /// <returns></returns>
        public int HasAdminUser(String account)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            return dal.HasAdminUser(account);

        }
        #endregion

        #region 通过用户名密码或取用户信息
        /// <summary>
        /// 通过用户名密码或取用户信息
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public T_AdminUser getUser(String account, String password)
        {
            T_AdminUserDAL dal = new T_AdminUserDAL();
            return dal.getUser(account, password);
        }
        #endregion

    }
}
